package com.estore.service;

import com.estore.model.Product;
import java.util.Comparator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ProductService {
    private final Map<String, Product> productData = new HashMap<>();

    /**
     * 构造函数，初始化商品数据
     */
    public ProductService() {
        productData.put("p001", new Product("p001", "Java从入门到精通", 99.0, 100));
        productData.put("p002", new Product("p002", "高性能MySQL", 128.5, 50));
        productData.put("p003", new Product("p003", "颈椎康复指南", 45.0, 200));
        productData.put("p004", new Product("p004", "生发秘籍", 88.0, 0));
    }

    /**
     * 获取所有商品列表
     */
    public List<Product> getAllProducts() {
        return new ArrayList<>(productData.values());
    }

    /**
     * 根据ID查找商品
     */
    public Product findProductById(String id) {
        return productData.get(id);
    }
}

// 将ProductSorters提取为独立的public类
